package com.apchernykh.rozhlasapp.player.fallback;

import java.io.IOException;

import com.apchernykh.rozhlasapp.ui.RozhlasAppBaseFragmentActivity;

import android.content.Context;

public class RozhlasNativeFallbackPlayer extends BaseFallbackPlayer implements
		IFallbackPlayer {
	protected String mStreamUri = null;

	@Override
	public boolean isValid() {
		return true;
	}

	public RozhlasNativeFallbackPlayer(Context iContext, String iUri) {
		super(iContext);
		mStreamUri = iUri;
	}

	@Override
	public void start() {
		if (mStreamUri == null) {
			return;
		}
		try {
			resetMediaPlayer(mStreamUri);
			mSeparateThreadMediaPlayer.prepareAsync();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			RozhlasAppBaseFragmentActivity.mApplicationModel.mInetInfo
					.signalInetFailure();
			e.printStackTrace();
		}
	}

	@Override
	public void stop() {
		if (mIsPrepared) {
			mIsPrepared = false;
			if (mSeparateThreadMediaPlayer != null) {
				mSeparateThreadMediaPlayer.stop();
			}
		}
		synchronized (this) {
			dispose();
		}
	}

}